package com.ziyun.erp.modules.goods.service.impl;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import com.ziyun.erp.modules.goods.dao.GoodsRecommendDao;
import com.ziyun.erp.modules.goods.entity.GoodsRecommendEntity;
import com.ziyun.erp.modules.goods.service.GoodsRecommendService;
import com.ziyun.erp.modules.goods.VO.GoodsRecommendVo;
import com.ziyun.erp.modules.goods.entity.GoodsEntity;
import io.renren.common.utils.R;

@Service("goodsRecommendService")
public class GoodsRecommendServiceImpl extends ServiceImpl<GoodsRecommendDao, GoodsRecommendEntity> implements GoodsRecommendService {

    @Override
    // 搜索/首页
    public PageUtils queryPage(Map<String, Object> params) {
        Page<GoodsRecommendVo> page = new Page<>(Integer.parseInt(params.get("page").toString()),
                Integer.parseInt(params.get("limit").toString()));
        page.setRecords(this.baseMapper.selectSourceList(page, params));

        return new PageUtils(page);
    }

    @Override
    public R saveGoodsRecommendInfo(GoodsRecommendEntity goodsRecommend) {
        Long goodsId = goodsRecommend.getGoodsId();
        int selectCount = this.selectCount(new EntityWrapper<>(new GoodsRecommendEntity()).eq("goods_id", goodsId));
        if (selectCount > 0) {
            return R.error("商品排序记录已存在");
        }

        baseMapper.insert(goodsRecommend);
        return R.ok();
    }

    /**
     * 修改
     */
    public void updateByAll(GoodsRecommendEntity goodsRecommend) {
        Integer id = goodsRecommend.getId();
        Integer showSort = goodsRecommend.getShowSort();
        Map<String, Object> map = new HashMap<>();
        map.put("showSort", showSort);
        baseMapper.updateByMap(map, id);
    }

    /**
     * 伪删除
     */
    public void deleteUpdate(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("disabled", 1);
        this.baseMapper.updateByMap(map, id);
    }
}
   
